<?php


/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Game
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
 
 
?>
<?php // echo date('r'); ?>
<?php // echo $this->locale()->toDateTime(date('Y-m-d h:i:s')); ?>
<script type="text/javascript">

var currentOrder = '<?php echo $this->order ?>';
var currentOrderDirection = '<?php echo $this->order_direction ?>';
var changeOrder = function(order, default_direction){
  // Just change direction
  if( order == currentOrder ) {
    $('order_direction').value = ( currentOrderDirection == 'ASC' ? 'DESC' : 'ASC' );
  } else {
    $('order').value = order;
    $('order_direction').value = default_direction;
  }
  $('game_admin_manage_filter').submit();
}


 // en4.core.runonce.add(function(){$$('th.admin_table_short input[type=checkbox]').addEvent('click', function(){ $$('input.checkboxes').set('checked', $(this).get('checked', false)); })});

  var delectSelected =function(){
    var checkboxes = $$('input[type=checkbox]');
    var selecteditems = [];

    checkboxes.each(function(item, index){
      var checked = item.get('checked', false);
      var value = item.get('value', false);
      if (checked == true && value != 'on'){
        selecteditems.push(value);
      }
    });

    $('ids').value = selecteditems;
    $('delete_selected').submit();
  }


function execGameFunction()
{
  var gtask = $("game_exec_task").getSelected().get("value");

  if (gtask == "") {
    alert('Please select the task you want to do.');
    return false;
  }
  else {
	    var checkboxes = $$('input.checkboxes');
	    var selecteditems = [];

	    checkboxes.each(function(item, index){
	    	var checked = item.get('checked');
	    	if (checked) {
	    		selecteditems.push(item.get('value'));
	    	}
	    });

    if (selecteditems == "") {
      alert("You have not selected any games yet.");
      return false;
    }  

    $('delete_selected').set('action', gtask);
    $('ids').value = selecteditems;
    $('delete_selected').submit();    
  }
}
function selectAll()
{
  var checkboxes = $$('input.checkboxes');
  var selecteditems = [];

  var chked = $('checkboxes_toggle').get('checked');
  
  checkboxes.each(function(item, index){
	  item.set('checked', chked);
  });
}
</script>

<h2><?php echo $this->translate("Game Plugin") ?></h2>

<?php if( count($this->navigation) ): ?>
  <div class='tabs'>
    <?php
      // Render the menu
      //->setUlClass()
      echo $this->navigation()->menu()->setContainer($this->navigation)->render()
    ?>
  </div>
<?php endif; ?>

<p>
  <?php echo $this->translate("TEST This page lists all of the games posted on your site. You can use this page to monitor these games and delete offensive material if necessary. Entering criteria into the filter fields will help you find specific games. Leaving the filter fields blank will show all the games on your social network.") ?>
</p>
<br />

<div>
    <?php echo $this->htmlLink($this->url(array('action'=>'create')), 
      $this->translate('Add New Game'),
      array('class' => 'buttonlink icon_game_create')
    )?> 
    <?php echo $this->htmlLink($this->url(array('controller'=>'distributors', 'action'=>'import', 'type'=>'mochi')), 
      $this->translate('Import Games'),
      array('class' => 'buttonlink icon_game_import')
    )?> 
    <?php echo $this->htmlLink($this->url(array('controller'=>'distributors', 'action'=>'fetch-csv')), 
      $this->translate('Fetch CSV Game Packs'),
      array('class' => 'buttonlink icon_game_fetch')
    )?> 
</div>
<br />

<div class='admin_search'>
  <?php echo $this->formFilter->render($this) ?>
</div>

<br />

<div class='admin_results'>
  <div>
    <?php $gameCount = $this->paginator->getTotalItemCount() ?>
    <?php echo $this->translate(array("%s game found", "%s games found", $gameCount), ($gameCount)) ?>
  </div>
  <div>
    <?php echo $this->paginationControl($this->paginator, null, null, array(
      'query' => $this->formValues
    )); ?>  
    
  </div>
</div>
<?php //print_r($this->params)?>
<br />

<?php if( count($this->paginator) ): ?>

<table class='admin_table' id='game_list_games'>
  <thead>
    <tr>
      <th class='admin_table_short'><input onclick="selectAll()" type='checkbox' id='checkboxes_toggle' /></th>
      <th class='admin_table_short'>ID</th>
      <th><?php echo $this->translate("Photo"); ?></th>
      <th class=''><?php echo $this->translate("Game") ?></th>
      <th style='width: 80px'><?php echo $this->translate("Category"); ?> [<a href="javascript:void(0);" onclick="Smoothbox.open($('game_icons_legend')); return false;">?</a>]</th>
      <th class=''><?php echo $this->translate("Created") ?></th>
      <th class=''><?php echo $this->translate("Icon") ?> [<a href="javascript:void(0);" onclick="Smoothbox.open($('game_icons_legend')); return false;">?</a>]</th>
      <th><?php echo $this->translate("Status")?></th>
      <th class='game_header_options'><?php echo $this->translate("Options") ?></th>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($this->paginator as $item): // $this->string()->chunk($item->getTitle(), 5) ?>
      <tr>
        <td><input type='checkbox' class='checkboxes' value="<?php echo $item->game_id ?>"/></td>
        <td><?php echo $item->game_id ?></td>
        <td><?php echo $this->itemPhoto($item, 'thumb.normal', $item->getTitle(), array('width'=>100))?></td>
        <td><?php echo $this->htmlLink($item->getHref(), $this->radcodes()->text()->truncate($item->getTitle(),32), array('target' => '_blank', 'class'=>'admin_table_bold')) ?>
        	<div><?php echo $this->viewMore($item->getDescription())?></div>
          <div class="game_text_desc">
            <?php echo $this->translate('by %s', $item->getOwner()->toString())?>
            |
                <?php echo $this->translate(array("%s view", "%s views", $item->view_count), $this->locale()->toNumber($item->view_count)); ?>
                - <?php echo $this->translate(array("%s comment", "%s comments", $item->comment_count), $this->locale()->toNumber($item->comment_count)); ?>
                - <?php echo $this->translate(array('%1$s like', '%1$s likes', $item->like_count), $this->locale()->toNumber($item->like_count)); ?>
                - <?php echo $this->translate(array("%s favorite", "%s favorites", $item->favorite_count), $this->locale()->toNumber($item->favorite_count)); ?>
          </div>
        </td>
        <td>
          <?php echo $item->getCategory()->toString(); ?>
          <div class="game_text_desc">
            R: <?php echo $item->getContentRating(); ?>
            <br />
            D: <?php echo $item->getDistributorType(); ?>
            <br />
            G: <?php echo $this->translate($item->swf_file_id ? 'Uploaded' : 'Hotlinked')?>
            <br />
            P: <?php echo $this->translate($item->photo_id ? 'Uploaded' : 'Hotlinked')?>
          </div>
          
        </td>
        <td>
          <?php echo $this->locale()->toDate($item->creation_date); ?>
        </td>   

        <td>
            <?php echo $this->htmlLink(
            array('route' => 'admin_default', 'module' => 'game', 'controller' => 'manage', 'action' => 'featured', 'game_id' => $item->game_id),
            $this->htmlImage('./application/modules/Game/externals/images/featured'.($item->featured ? "" : "_off").'.png'),
            array('class' => 'smoothbox', 'title' => $this->translate($item->featured ? "Featured" : "Not Featured"))) ?>
            <?php echo $this->htmlLink(
            array('route' => 'admin_default', 'module' => 'game', 'controller' => 'manage', 'action' => 'sponsored', 'game_id' => $item->game_id),
            $this->htmlImage('./application/modules/Game/externals/images/sponsored'.($item->sponsored ? "" : "_off").'.png'),
            array('class' => 'smoothbox', 'title' => $this->translate($item->sponsored ? "Sponsored" : "Not Sponsored"))) ?>
        
            <br />
            
            <?php echo $this->htmlImage('./application/modules/Game/externals/images/leaderboard'.($item->leaderboard_enabled ? "" : "_off").'.png') ?>
        </td>
        <td>
					<?php echo $this->htmlLink(
            array('route' => 'admin_default', 'module' => 'game', 'controller' => 'manage', 'action' => 'update-status', 'game_id' => $item->game_id),
            $this->translate($item->status),
            array('class' => 'smoothbox')) ?>
        </td>        
        <td>
          <?php echo $this->htmlLink(
            array('route' => 'admin_default', 'module' => 'game', 'controller' => 'manage', 'action' => 'edit', 'game_id' => $item->game_id),
            $this->translate("edit"),
            array()) ?>          |
          <?php echo $this->htmlLink(
            array('route' => 'admin_default', 'module' => 'game', 'controller' => 'manage', 'action' => 'delete', 'game_id' => $item->game_id),
            $this->translate("delete"),
            array('class' => 'smoothbox')) ?>
           
          <br />
          <?php echo $this->htmlLink(
            array('route' => 'admin_default', 'module' => 'game', 'controller' => 'manage', 'action' => 'preview', 'game_id' => $item->game_id),
            $this->translate("preview game"),
            array('class' => 'smoothbox')) ?>
          <?php if ($item->swf_url || $item->thumbnail_url): ?>   
            <br />
            <?php echo $this->htmlLink(
              array('route' => 'admin_default', 'module' => 'game', 'controller' => 'manage', 'action' => 'download', 'game_id' => $item->game_id),
              $this->translate("download files"),
              array('class' => 'smoothbox')) ?>
          <?php endif; ?>  
          <?php if (($item->swf_url && $item->swf_file_id) || ($item->thumbnail_url && $item->photo_id)): ?>
            <br />
            <?php echo $this->htmlLink(
              array('route' => 'admin_default', 'module' => 'game', 'controller' => 'manage', 'action' => 'remove', 'game_id' => $item->game_id),
              $this->translate("remove files"),
              array('class' => 'smoothbox')) ?>
          <?php endif; ?>  
        </td>
      </tr>
    <?php endforeach; ?>
  </tbody>
</table>

<br />

<div>

</div>

<div class='buttons'>

  <?php echo $this->translate('With selected games,') ?>
  <select name="game_exec_task" id="game_exec_task">
    <option value=""><?php echo $this->translate('Perform the following action:')?></option>
    <option value="<?php echo $this->url(array('module'=>'game','controller'=>'manage','action'=>'deleteselected'),'admin_default',true) ?>"><?php echo $this->translate('Delete selected games')?></option>
    <option value="<?php echo $this->url(array('module'=>'game','controller'=>'manage','action'=>'update-status-selected','status'=>'published'),'admin_default',true) ?>"><?php echo $this->translate('Set status to Published')?></option>
    <option value="<?php echo $this->url(array('module'=>'game','controller'=>'manage','action'=>'update-status-selected','status'=>'disabled'),'admin_default',true) ?>"><?php echo $this->translate('Set status to Disabled')?></option>
    <option value="<?php echo $this->url(array('module'=>'game','controller'=>'manage','action'=>'update-status-selected','status'=>'pending'),'admin_default',true) ?>"><?php echo $this->translate('Set status to Pending')?></option>
    
    <option value="<?php echo $this->url(array('module'=>'game','controller'=>'manage','action'=>'download-selected','type'=>'both'),'admin_default',true) ?>"><?php echo $this->translate('Download both swf and photo files')?></option>
    <option value="<?php echo $this->url(array('module'=>'game','controller'=>'manage','action'=>'download-selected','type'=>'swf'),'admin_default',true) ?>"><?php echo $this->translate('Download swf files')?></option>
    <option value="<?php echo $this->url(array('module'=>'game','controller'=>'manage','action'=>'download-selected','type'=>'photo'),'admin_default',true) ?>"><?php echo $this->translate('Download photo files')?></option>
  
    <option value="<?php echo $this->url(array('module'=>'game','controller'=>'manage','action'=>'remove-selected','type'=>'both'),'admin_default',true) ?>"><?php echo $this->translate('Remove both swf / photo files if file URLs are provided')?></option>
    <option value="<?php echo $this->url(array('module'=>'game','controller'=>'manage','action'=>'remove-selected','type'=>'swf'),'admin_default',true) ?>"><?php echo $this->translate('Remove uploaded swf files if swf urls are provided')?></option>
    <option value="<?php echo $this->url(array('module'=>'game','controller'=>'manage','action'=>'remove-selected','type'=>'photo'),'admin_default',true) ?>"><?php echo $this->translate('Remove uploaded photo files if photo urls are provided')?></option>  
  
  </select>
  
  <button type='submit' onclick="javascript:execGameFunction();">
    <?php echo $this->translate("Submit"); ?>
  </button>
<?php /*
  <button onclick="javascript:massUpdateGames('<?php echo $this->url(array('module'=>'game','controller'=>'manage','action'=>'deleteselected'),'admin_default',true) ?>');" type='submit'>
    <?php echo $this->translate("Delete Selected") ?>
  </button>
  
  <button onclick="javascript:massUpdateGames('<?php echo $this->url(array('module'=>'game','controller'=>'manage','action'=>'update-status-selected','status'=>'published'),'admin_default',true) ?>');" type='submit'>
    <?php echo $this->translate("Publish Selected") ?>
  </button>  
  <button onclick="javascript:massUpdateGames('<?php echo $this->url(array('module'=>'game','controller'=>'manage','action'=>'update-status-selected','status'=>'disable'),'admin_default',true) ?>');" type='submit'>
    <?php echo $this->translate("Disable Selected") ?>
  </button> 
  */ ?>
</div>

<form id='delete_selected' method='post' action='<?php echo $this->url(array('action' =>'deleteselected')) ?>'>
  <input type="hidden" id="ids" name="ids" value=""/>
</form>
<br/>

<div class='admin_results'>
  <div>
    <?php $gameCount = $this->paginator->getTotalItemCount() ?>
    <?php echo $this->translate(array("%s game found", "%s games found", $gameCount), ($gameCount)) ?>
  </div>
  <div>
    <?php echo $this->paginationControl($this->paginator, null, null, array(
      'query' => $this->formValues
    )); ?>  
    
  </div>
</div>
<br/>
<?php //print_r($this->params)?>
<?php else:?>
  <div class="tip">
    <span>
      <?php echo $this->translate("There are no games posted by your members yet.") ?>
    </span>
  </div>
<?php endif; ?>


<div style="display: none">
    
  <ul class="radcodes_admin_icons_legend" id="game_icons_legend">
    <li><?php echo $this->htmlImage('./application/modules/Game/externals/images/leaderboard.png');?><?php echo $this->translate('Leaderboard Enabled')?></li>
    <li><?php echo $this->htmlImage('./application/modules/Game/externals/images/leaderboard_off.png');?><?php echo $this->translate('Leaderboard Disabled')?></li>  
    <li><?php echo $this->htmlImage('./application/modules/Game/externals/images/featured.png');?><?php echo $this->translate('Featured')?></li>
    <li><?php echo $this->htmlImage('./application/modules/Game/externals/images/featured_off.png');?><?php echo $this->translate('Not Featured')?></li>
    <li><?php echo $this->htmlImage('./application/modules/Game/externals/images/sponsored.png');?><?php echo $this->translate('Sponsored')?></li>
    <li><?php echo $this->htmlImage('./application/modules/Game/externals/images/sponsored_off.png');?><?php echo $this->translate('Not Sponsored')?></li>  
    <li>
      R: Content Rating
      <br/>D: Distributor Type
      <br/>G: Game SWF File
      <br/>P: Game Photo File
    </li>
  </ul>
  
</div>
